package com.fei.hunqing.util;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;

import java.util.Base64;

public class PassUtil {
    /**
     * 生成AES的密钥
     * @return 密钥*/
    public static String createAESKey(){
        return Base64.getEncoder().encodeToString(SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded());
    }
    /**
     * AES加密
     * @param key 密钥
     * @param pass 要加密的明文
     * @return AES解密后的结果*/
    public static String aesEnc(String key,String pass){
        return new SymmetricCrypto(SymmetricAlgorithm.AES, Base64.getDecoder().decode(key)).encryptBase64(pass);
    }
    /**
     * AES解密
     * @param key 密钥
     * @param pass 要解密的密文
     * @return 解密后的结果*/
    public static String aesDec(String key,String pass){
        return new SymmetricCrypto(SymmetricAlgorithm.AES, Base64.getDecoder().decode(key)).decryptStr(pass);
    }
}
